define(["lib/swipeslider.min"], function () {
    //ly 渲染数据
    function request(){
        var id = App.input(1);
        var url = App.url('gatewory?mod=Shop&cla=IndexController&act=buyservice');
        App.get(url,{
            param:{
                id:id
            }
        },function(d){
            if(d.code == 1000)
            rendor(d.data);
        });
    }
    function rendor(d){
        var cover = d.shop_buyservice.service.cover;
        var tmp  = cover.split("#");
        d.service_cover = typeof tmp === "object"?tmp:[cover];
        App.log(d);
        App.load_view("page/serviceDetail/index",{d:d});
    }
    App.myApp.onPageInit("page.serviceDetail.index", function () {
        // navbar白色
        $('.navbar').removeClass('navbar-scroll');
        // banner滚动
        $('#banner-service-detail').swipeslider({
            autoPlay: !1
        });
        // 右上角菜单栏
        var i = 0;
        $('.service-detail-menu').click(function(){
            $('.service-detail-menu-list').toggle();
        });

        // 顶部点击
        var bannerServiceDetail = $('#banner-service-detail').offset().top-44;
        var serviceDetails = $('#service-details').offset().top-44;
        var evaluationBox = $('#evaluation-box').offset().top-44;
        var customLogo = $('#custom-logo').offset().top-44;
        var interval = setInterval(function(){
            if($('.service-detail-scroll').scrollTop() > 0){
                clearInterval(interval);
            }else{
                evaluationBox = $('#evaluation-box').offset().top-44;
                customLogo = $('#custom-logo').offset().top-44;
            }
        },100);

        $('.service-detail-tab li').on('click',function(){
            var currentId = $(this).children('a').attr('href').substring(1);
            if(currentId == 'bannerServiceDetail'){
                $('.service-detail-scroll').animate({
                    scrollTop: bannerServiceDetail+1
                },500);
            }
            if(currentId == 'serviceDetails'){
                $('.service-detail-scroll').animate({
                    scrollTop: serviceDetails+1
                },500);
            }
            if(currentId == 'evaluationBox'){
                $('.service-detail-scroll').animate({
                    scrollTop: evaluationBox+1
                },500);
            }
            if(currentId == 'customLogo'){
                $('.service-detail-scroll').animate({
                    scrollTop: customLogo+1
                },500);
            }
        });

        // 页面滚动navbar切换
        $('.service-detail-scroll').scroll(function () {
            if($(this).scrollTop() > customLogo){
                $('.service-detail-tab li').removeClass('active');
                $('.customLogo').addClass('active');
            }else if($(this).scrollTop() > evaluationBox){
                $('.service-detail-tab li').removeClass('active');
                $('.evaluationBox').addClass('active');
            }else if($(this).scrollTop() > serviceDetails){
                $('.service-detail-tab li').removeClass('active');
                $('.serviceDetails').addClass('active');
            }else{
                $('.service-detail-tab li').removeClass('active');
                $('.bannerServiceDetail').addClass('active');
            }
        });
        // 定制LOGO服务滑动
        var trackBarVal = parseInt($('#trackBar').val());
        var trackBarMin = parseInt($('#trackBar').attr('min'));
        var trackBarMax = parseInt($('#trackBar').attr('max'));
        var intentionPrice = $('.intention-price>span');
        var percent = (trackBarVal - trackBarMin) / (trackBarMax - trackBarMin) * 100;
        intentionPrice.text('￥'+trackBarVal);
        $('#trackBar').css( {'background-size':percent + '% 100%' });
        $('#trackBar').on('input',function(){
            var percent = ($(this).val() - $(this).attr('min')) / ($(this).attr('max') - $(this).attr('min')) * 100;
            $(this).css( {'background-size':percent + '% 100%' });
            intentionPrice.text('￥'+$(this).val());
            $('#trackBar-value').val($(this).val());
        });
        $('#trackBar-value').on('input',function(){
            if($(this).val() == ''){
                $('#trackBar').val(trackBarMin);
                intentionPrice.text('￥'+trackBarMin);
            }else{
                if(parseInt($(this).val()) < trackBarMin){
                    $('#trackBar').val(trackBarMin);
                    intentionPrice.text('￥'+trackBarMin);
                }else if(parseInt($(this).val()) > trackBarMax){
                    $('#trackBar').val(trackBarMax);
                    intentionPrice.text('￥'+trackBarMax);
                }else{
                    $('#trackBar').val($(this).val());
                    intentionPrice.text('￥'+$(this).val());
                }
            }
            var percent = (parseInt($('#trackBar').val()) -trackBarMin) / (trackBarMax - trackBarMin) * 100;
            $('#trackBar').css( {'background-size':percent + '% 100%' });
        });
    });
    return request();
});